package io.adrainty.algorithm.leetcode.normal;

/**
 * @author adrainty
 * @version v1.0.0
 * @since 2024/12/27 上午10:56
 */
public class Solution152 {

    public int maxProduct(int[] nums) {
        int[][] dp = new int[nums.length][2];
        dp[0][0] = nums[0];
        dp[0][1] = nums[0];

        for (int i = 1; i < nums.length; i++) {
            dp[i][0] = Math.max(dp[i - 1][0] * nums[i], nums[i]);
            dp[i][0] = Math.max(dp[i - 1][1] * nums[i], dp[i][0]);

            dp[i][1] = Math.min(dp[i - 1][0] * nums[i], nums[i]);
            dp[i][1] = Math.min(dp[i - 1][1] * nums[i], dp[i][1]);
        }

        int max = dp[0][0];
        for (int i = 1; i < nums.length; i++) {
            max = Math.max(max, dp[i][0]);
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(new Solution152().maxProduct(new int[]{-2,3,-4}));
    }
}
